# Maintainer: Christian Rebischke <chris.rebischke@archlinux.org>
# Maintainer: Daurnimator <daurnimator@archlinux.org>

pkgname=kustomize
pkgver=5.2.1
pkgrel=1
pkgdesc="Template-free customization of Kubernetes YAML manifests"
arch=('loong64' 'x86_64')
url="https://github.com/kubernetes-sigs/kustomize"
license=('Apache')
makedepends=('go')
depends=('glibc')
optdepends=('helm')
options=('!lto')
source=("https://github.com/kubernetes-sigs/kustomize/archive/kustomize/v${pkgver}/${pkgname}-${pkgver}.tar.gz")
sha512sums=('8d9147131f242fa03d9ad95161419f0ed47f522976cfbc3cb9c9a71f0f2e983e58139eba4881819cb395ae1ee044601bbb9ae3a85216313caba0f051f1ae52d7')
b2sums=('150de8bf741ef33f1e8188d45d3bb2bf3d5c03b59be9029d1b79bb9996e6237f7e65ec09fc44532afa882c379d39f1cb2ed142d79358b4d926da43e5e7f8dfee')

prepare() {
  cd "kustomize-kustomize-v${pkgver}/kustomize"

  GOPATH="${srcdir}"
  go mod download
}

build(){
  cd "kustomize-kustomize-v${pkgver}/kustomize"

  export CGO_LDFLAGS="${LDFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  GOPATH="${srcdir}"
  export GOPROXY=off
  go build \
    -trimpath \
    -buildmode=pie \
    -mod=readonly \
    -modcacherw \
    -ldflags " \
      -X sigs.k8s.io/kustomize/api/provenance.version=${pkgver} \
      -X sigs.k8s.io/kustomize/api/provenance.buildDate=$(date -u +'%Y-%m-%dT%H:%M:%SZ' --date=@${SOURCE_DATE_EPOCH}) \
      -compressdwarf=false \
      -extldflags ${LDFLAGS}" \
    .
}

check(){
  cd "kustomize-kustomize-v${pkgver}/kustomize"

  go test ./...
}

package(){
  cd "kustomize-kustomize-v${pkgver}/kustomize"

  # install completions
  mkdir -p "${pkgdir}/usr/share/bash-completion/completions"
  ./kustomize completion bash >  "${pkgdir}/usr/share/bash-completion/completions/kustomize"
  mkdir -p "${pkgdir}/usr/share/zsh/site-functions/"
  ./kustomize completion zsh >  "${pkgdir}/usr/share/zsh/site-functions/_kustomize"
  mkdir -p "${pkgdir}/usr/share/fish/vendor_completions.d"
  ./kustomize completion fish >  "${pkgdir}/usr/share/fish/vendor_completions.d/kustomize.fish"

  # install binary
  install -D kustomize "${pkgdir}/usr/bin/kustomize"
}

# vim: ts=2 sw=2 et:
